﻿--[[
   @brief    descprtion: badge_detail_view
   @author   hanmanhuang
   @version  1.0
   @date     2016-07-08
--]]

badge_detail_view = 
{
    init = function()
    end;

    inner_log = function (msg, core_msg)
        base_utility.log(string.format("[badge_detail_view] %s", msg), core_msg);
    end;

    open_page = function()
        local pPageDlg = nil;
        local nPageDlg = ui_utility.get_ctrl_id_by_cid(CID_BADGE_DETAIL_DLG);
        if nPageDlg == Tenio.INVALID_CONTROLID then
            layout_mgr.restore_layout("BadgeDetailWnd.tpf");
        else
            pPageDlg = ui_utility.get_ctrl_ptr_by_cid(CID_BADGE_DETAIL_DLG);
            if nil ~= pPageDlg then
                badge_detail_view.show_web_ctn(false);
                pPageDlg:Show(FALSE);
            end
        end;

        local pPageDlg = ui_utility.get_ctrl_ptr_by_cid(CID_BADGE_DETAIL_DLG);
        if (nil ~= pPageDlg) then    
            badge_detail_view.load_page();
            badge_detail_view.show_page();
        end;
    end;

    load_page = function()
        badge_detail_view.inner_log("load_page");

        local pControl = ui_utility.get_ctrl_ptr_by_cid(CID_BADGE_DETAIL_DLG_QBWEB);
        if nil ~= pControl then
            local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
            local url = badge_detail_control.get_page_url();
            local const_ui_str = U8toCUIStr(url);
            pQBWeb:Navigate(const_ui_str);
        end;
    end;

    show_page = function()
        base_utility.log("show_page");

        local nPageDlg = ui_utility.get_ctrl_id_by_cid(CID_BADGE_DETAIL_DLG);
        if nPageDlg == Tenio.INVALID_CONTROLID then
            return;
        end;

        local pPageDlg = ui_utility.get_ctrl_ptr_by_cid(CID_BADGE_DETAIL_DLG);
        if (nil ~= pPageDlg) then
            pPageDlg:MoveToCenter(); 
            pPageDlg:Show(TRUE);
            pPageDlg:BringToTop();
            pPageDlg:SetFocus();
        end;
    end;

    show_web_ctn = function(bshow)
        local nPageDlg = ui_utility.get_ctrl_id_by_cid(CID_BADGE_DETAIL_DLG_QBWEB);
        if Tenio.INVALID_CONTROLID == nPageDlg then
            return;
        end;

        if bshow == true then
            ui_utility.setproperty_by_id(nPageDlg, "Visible", "true");
        else
            ui_utility.setproperty_by_id(nPageDlg, "Visible", "false");
        end
    end;

    close_page = function()
        local pPageDlg = ui_utility.get_ctrl_ptr_by_cid(CID_BADGE_DETAIL_DLG);
        if (nil ~= pPageDlg) then
            pPageDlg:Show(FALSE);
        end;

        local nPageDlg = ui_utility.get_ctrl_id_by_cid(CID_BADGE_DETAIL_DLG);
        if nPageDlg ~= Tenio.INVALID_CONTROLID then
            layout_mgr.delay_remove_ctrl(nPageDlg);
        end
    end;
};

badge_detail_view.init();

